package com.axend.aerosense.main.ui.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ChenHongWei
 * @date :2020/12/18 10:21
 */

public class Page2Adapter extends FragmentStateAdapter {

    private List<Fragment> fragments = new ArrayList<>();

    public Page2Adapter(@NonNull FragmentActivity fragmentActivity) {
        super(fragmentActivity);
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        if (fragments != null){
           return fragments.get(position);
        }
        return null;
    }

    @Override
    public int getItemCount() {
        int count = fragments.size();
        return count == 0 ? 0 : count;
    }

    /**
     * 动态设置fragment
     * @param fragments
     */
    public void setFragments(List<Fragment> fragments) {
        this.fragments = fragments;
    }
}
